package com.atguigu.scala.chapter7

/**
 * @author lizikuan
 * @date 2021/5/24 16:51
 */
object $09_WordCountHigh {
  def main(args: Array[String]): Unit = {
    val tupleList = List(("Hello Scala Spark World", 4), ("Hello Scala Spark", 3), ("Hello Scala", 2), ("Hello", 1))

    //1、切割+压平,给单词赋予初始次数
    val list = tupleList.flatMap(x => {
      x._1.split(" ").map(y=>y->x._2)
    })
    //2、按照单词分组
    val list2 = list.groupBy(x => x._1)
    println(list2)
    //3、统计单词个数
   list2.map(x => x._1 -> x._2.map(x=>x._2).sum).foreach(x=>println(x))
    //4、结果展示
  }
}
